import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    list: [
      {
        title: "再有三天考试",
        user: "sundy",
      },
      {
        title: "再有两天过中秋",
        user: "sundy",
      },
      {
        title: "十一过后大家就转七了",
        user: "小可爱",
      },
    ],
  },
  mutations: {
    add(state, obj) {
      state.list.push(obj);
    },
    //vuex里的添加
    remove(state, index) {
      state.list.splice(index, 1);
    },
    //vuex里的删除
    update(state, obj) {
      state.list[obj.index].title = obj.title;
      state.list[obj.index].user = obj.user;
    },
    //vuex里的删除
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
});
